/**
 * Created by wyy on 17-7-19.
 */
angular.module('toolBar', []).component(
    'toolBar',
    {
        templateUrl: 'component/base/toolBar/tool_bar.template.html',
        controller: ['$rootScope', '$scope', 'Api', 'Enum', '$state', 'CompanyModel',
            function ($rootScope, $scope, Api, Enum, $state, CompanyModel) {

                $scope.clickDelete = clickDelete;
                $scope.CheckIn = CheckIn;
                $scope.updateStatus = updateStatus;
                $rootScope.$watch('apamentInfo',function(apamentInfo){
                    if(apamentInfo){
                        getBtnStatus(apamentInfo.status)
                    }
                });
                function clickDelete() {
                    $scope.$parent.clickDelete();
                    // $state.go('company.companyApartmentManage');
                }

                function CheckIn() {
                    $scope.$parent.CheckIn();
                }

                function updateStatus(status) {
                    var data = {
                        value : status
                    };
                    console.log(data)
                    Api.changeApartmentStatus($rootScope.apamentInfo.id, data ,function(result){
                        console.log(result)
                        location.reload()
                    });
                }

                function getBtnStatus(status) {
                    if (status == 'FREE') {
                        $scope.freeBtnAble = true;
                        $scope.offLineBtnAble = false;
                        $scope.checkBtnAble = false;
                        $scope.deleteBtnAble = false;

                    } else if (status == 'OFFLINE') {
                        $scope.freeBtnAble = false;
                        $scope.offLineBtnAble = false;
                        $scope.checkBtnAble = true;
                        $scope.deleteBtnAble = false;

                    } else if (status == 'CHECK') {
                        $scope.freeBtnAble = true;
                        $scope.offLineBtnAble = true;
                        $scope.checkBtnAble = true;
                        $scope.deleteBtnAble = true;
                    }
                    var $navButton =$('.nav-button');
                    $navButton.find('button').removeClass('active');
                    $navButton.find('button[name='+ status+']').addClass('active')
                }
            }]
    }
)

